package com.bdc.service;

import java.io.DataInputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import com.bdc.BdcVar;
import com.bdc.activity.PostExecutor;
import com.bdc.domain.RecordInfo;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;

public class BdcService {

	private static SharedPreferences sharedPreferences ;
	private static final BdcService bdService = new BdcService() ;
	private static long userId ;
	private static List<RecordInfo> todayRecordList ;
	
	private BdcService(){}
	
	public static BdcService getInstance(){
		return bdService ;
	}
	
	public static void init(Context context){
		sharedPreferences = context.getSharedPreferences("setting", Context.MODE_PRIVATE) ;
		todayRecordList = new ArrayList<RecordInfo>() ;
	}

	//验证用户
	public AsyncTask verifyUser(String userName, String password, final PostExecutor postExecutor){
		AsyncTask task = new AsyncTask<String, Void, Long>(){

			@Override
			protected Long doInBackground(String... params) {
				
				
				return null ;
			}

			@Override
			protected void onPostExecute(Long result) {
				postExecutor.postExecute(result) ;
			}
			
		}.execute(userName, password) ;
		
		return task ;
	}
	
	public RecordInfo getNextRecord(){
		for(RecordInfo record : todayRecordList){
			if(record.getScore()<BdcVar.SCORE_REMEMBER)
				return record ;
		}
		
		return null ;
	}
	
}
